package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.DynamicProblem;

/**
 * @author tzp
 * @since 2020/9/15
 */
public class LC279 implements DynamicProblem {
    public int numSquares(int n) {
        if (n <= 1) return 1;
        int[] state = new int[n + 1];
        state[1] = 1;
        for (int i = 2; i <= n; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = 1; j * j <= i; j++) {
                min = Math.min(min, state[i - j * j]);
            }
            state[i] = min + 1;
        }
        return state[n];
    }

    public static void main(String[] args) {
        //12 = 4 + 4 + 4.
        //13 = 4 + 9.
        System.out.println(new LC279().numSquares(12));
        System.out.println(new LC279().numSquares(13));
    }
}
